﻿<%@ CodePage = 65001 %>


<!--#include file="includes/database.asp" -->
<!--#include file="includes/global_varaiable.asp" -->
<!--#include file="giochieu_info.asp" -->


<%
Response.expires = 0
Response.expiresabsolute = Now() - 1
Response.addHeader "pragma", "no-cache"
Response.addHeader "cache-control", "private"
Response.addHeader "cache-control", "no-cache"
Response.addHeader "cache-control", "no-store"
Response.CacheControl = "no-cache"

nStartRec = 0
nStopRec = 0
nTotalRecs = 0
nRecCount = 0
nRecActual = 0
sDeleteConfirmMsg = "Bạn có chắc chắn muốn xóa tất cả những dữ liệu đã chọn không?"
nDisplayRecs = 20
nRecRange = 10

Dim t_SessionID

Const StartRec = "start"
Const SessionStartRec = "giochieu_start"
Const ewSessionMessage = "Message"

' Set Up Inline Edit Parameters
sAction = ""
SetUpInlineEdit()

%>
<!--#include file="header.asp"-->

<script type="text/javascript" src="ew.js"></script>

<script type="text/javascript">
<!--
function EW_checkMyForm(EW_this) {
if (EW_this.x_GiochieuID && !EW_hasValue(EW_this.x_GiochieuID, "TEXT" )) {
	if (!EW_onError(EW_this, EW_this.x_GiochieuID, "TEXT", "Vui lòng nhập dữ liệu - Session ID"))
		return false;
}
if (EW_this.x_GiochieuID && !EW_checkinteger(EW_this.x_GiochieuID.value)) {
	if (!EW_onError(EW_this, EW_this.x_GiochieuID, "TEXT", "Session ID phải là số"))
		return false; 
}
if (EW_this.x_Mota && !EW_hasValue(EW_this.x_Mota, "TEXT" )) {
	if (!EW_onError(EW_this, EW_this.x_Mota, "TEXT", "Vui lòng nhập dữ liệu - Description"))
		return false;
}
if (EW_this.x_gioBD && !EW_hasValue(EW_this.x_gioBD, "TEXT" )) {
	if (!EW_onError(EW_this, EW_this.x_gioBD, "TEXT", "Vui lòng nhập dữ liệu - Hour Start"))
		return false;
}
if (EW_this.x_gioBD && !EW_checkinteger(EW_this.x_gioBD.value)) {
	if (!EW_onError(EW_this, EW_this.x_gioBD, "TEXT", "Hour Start phải là số"))
		return false; 
}
if (EW_this.x_phutBD && !EW_hasValue(EW_this.x_phutBD, "TEXT" )) {
	if (!EW_onError(EW_this, EW_this.x_phutBD, "TEXT", "Vui lòng nhập dữ liệu - Minute Start"))
		return false;
}
if (EW_this.x_phutBD && !EW_checkinteger(EW_this.x_phutBD.value)) {
	if (!EW_onError(EW_this, EW_this.x_phutBD, "TEXT", "Minute Start phải là số"))
		return false; 
}
return true;
}
//-->
</script>

<script type="text/javascript">
<!--
function EW_selectKey(elem) {
	var f = elem.form;	
	if (!f.key_d) return;
	if (f.key_d[0]) {
		for (var i=0; i<f.key_d.length; i++)
			f.key_d[i].checked = elem.checked;	
	} else {
		f.key_d.checked = elem.checked;	
	}
	ew_clickall(elem);
}
function EW_selected(elem) {
	var f = elem.form;	
	if (!f.key_d) return false;
	if (f.key_d[0]) {
		for (var i=0; i<f.key_d.length; i++)
			if (f.key_d[i].checked) return true;
	} else {
		return f.key_d.checked;
	}
	return false;
}
//-->
</script>
<%

sSQL = "SELECT * FROM GIOCHIEU"

' Set up Record Set
Set rs = Server.CreateObject("ADODB.Recordset")
rs.CursorLocation = 3
rs.Open sSql, adoCon, 1, 2
nTotalRecs = rs.RecordCount
If nDisplayRecs <= 0 Then ' Display All Records
	nDisplayRecs = nTotalRecs
End If
nStartRec = 1
SetUpStartRec() ' Set Up Start Record Position
%>
<p><span class="aspmaker">TABLE: GIOCHIEU</span></p>

<%
If Session(ewSessionMessage) <> "" Then
%>
<p><span class="ewmsg"><%= Session(ewSessionMessage) %></span></p>
<%
	Session(ewSessionMessage) = "" ' Clear message
End If
%>

<table class="ewListAdd">
	<tr>
		<td><span class="aspmaker"><a href="giochieu_add.asp">Add</a></span></td>
	</tr>
</table>
<p>
<% If nTotalRecs > 0 Then %>
<form name="giochieu_list" id="giochieu_list" action="giochieu_list.asp" method="post">
<table id="ewlistmain" class="ewTable">
	<!-- Table header -->
	<tr class="ewTableHeader">
		<td valign="top"><span>Session ID</span></td>
		<td valign="top"><span>Description</span></td>
		<td valign="top"><span>Hour Start</span></td>
		<td valign="top"><span>Minute Start</span></td>
<td>&nbsp;</td>
<td><input type="checkbox" class="aspmaker" onClick="EW_selectKey(this);"></td>
	</tr>
<%

' Avoid starting record > total records
If CLng(nStartRec) > CLng(nTotalRecs) Then
	nStartRec = nTotalRecs
End If

' Set the last record to display
nStopRec = nStartRec + nDisplayRecs - 1

' Move to first record directly for performance reason
nRecCount = nStartRec - 1
If Not rs.Eof Then
	rs.MoveFirst
	rs.Move nStartRec - 1
End If
nEditRowCnt = 0
nRecActual = 0
Do While (Not rs.Eof) And (nRecCount < nStopRec)
	nRecCount = nRecCount + 1
	If CLng(nRecCount) >= CLng(nStartRec) Then
		nRecActual = nRecActual + 1

	' Set row color
	sItemRowClass = " class=""ewTableRow"""
	
	' Display alternate color for rows
	If nRecCount Mod 2 <> 1 Then
		sItemRowClass = " class=""ewTableAltRow"""
	End If
	x_GiochieuID = rs("SessionID")
	x_Mota = rs("Description")
	x_gioBD = rs("HourStart")
	x_phutBD = rs("MinuteStart")
	bEditRow = (CStr(Session(ewSessionTblKey & "_GiochieuID")&"") = CStr(x_GiochieuID&"")) And (nEditRowCnt = 0)
	If bEditRow Then
		nEditRowCnt = nEditRowCnt + 1
		sItemRowClass = " class=""ewTableEditRow"""
		
	End If
%>
	<!-- Table body -->
	<tr<%=sItemRowClass%><%=sListTrJs%>>
		<!-- GiochieuID -->
		<td><span>
<% If bEditRow Then ' Edit Record 
%>

<% Response.Write x_GiochieuID %><input type="hidden" id="x_GiochieuID" name="x_GiochieuID" value="<%= x_GiochieuID %>">
<% Else %>
<% Response.Write x_GiochieuID %>
<% End If %>
</span></td>
		<!-- Mota -->
		<td><span>
<% If bEditRow Then ' Edit Record 
%>

<input type="text" name="x_Mota" id="x_Mota" size="30" maxlength="50" value="<%= Server.HTMLEncode(x_Mota&"") %>">
<% Else %>
<% Response.Write x_Mota %>
<% End If %>
</span></td>
		<!-- gioBD -->
		<td><span>
<% If bEditRow Then ' Edit Record 
%>

<input type="text" name="x_gioBD" id="x_gioBD" size="30" value="<%= Server.HTMLEncode(x_gioBD&"") %>">
<% Else %>
<% Response.Write x_gioBD %>
<% End If %>
</span></td>
		<!-- phutBD -->
		<td><span>
<% If bEditRow Then ' Edit Record 
%>

<input type="text" name="x_phutBD" id="x_phutBD" size="30" value="<%= Server.HTMLEncode(x_phutBD&"") %>">
<% Else %>
<% Response.Write x_phutBD %>
<% End If %>
</span></td>
<td><span class="aspmaker">
<% If CStr(Session(ewSessionTblKey & "_GiochieuID")&"") = CStr(x_GiochieuID&"") Then %>
<a href="" onClick="if (EW_checkMyForm(document.giochieu_list)) document.giochieu_list.submit();return false;">Update</a>&nbsp;<a href="giochieu_list.asp?a=cancel">Cancel</a>
<input type="hidden" name="a_list" value="update">
<% Else %>
<a href="<% If Not IsNull(x_GiochieuID) Then Response.Write "giochieu_list.asp?a=edit&GiochieuID=" & Server.URLEncode(x_GiochieuID) Else Response.Write "javascript:alert('Invalid Record! Key is null');" End If %>">Inline Edit</a>
<% End If %>
</span></td>
<td><span class="aspmaker"><input type="checkbox" name="key_d" value="<%= x_GiochieuID %>" class="aspmaker" onclick='ew_clickmultidelete(this);'>Delete</span></td>
	</tr>
<%
	End If
	rs.MoveNext
Loop
%>
</table>
<% If nRecActual > 0 Then %>
<p>
<input type="button" name="btndelete" value="DELETE SELECTED" onClick="if (!EW_selected(this)) alert('Bạn chưa chọn dữ liệu để xóa!'); else if (ew_confirm('<%=sDeleteConfirmMsg%>')) {this.form.action='giochieu_delete.asp';this.form.encoding='application/x-www-form-urlencoded';this.form.submit();}">
<p>
<% End If %>
</form>
<% If LCase(sAction) = "edit" Then %>
<% End If %>
<% End If %>
<%

' Close recordset and adoConection
rs.Close
Set rs = Nothing
adoCon.Close
Set adoCon = Nothing
%>
<form action="giochieu_list.asp" name="ewpagerform" id="ewpagerform">
<table border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td nowrap>
<%
If nTotalRecs > 0 Then
	rsEof = (nTotalRecs < (nStartRec + nDisplayRecs))
	PrevStart = nStartRec - nDisplayRecs
	If PrevStart < 1 Then PrevStart = 1
	NextStart = nStartRec + nDisplayRecs
	If NextStart > nTotalRecs Then NextStart = nStartRec
	LastStart = ((nTotalRecs-1)\nDisplayRecs)*nDisplayRecs+1
	%>
	<table border="0" cellspacing="0" cellpadding="0"><tr><td><span class="aspmaker">Page&nbsp;</span></td>
<!--first page button-->
	<% If CLng(nStartRec)=1 Then %>
	<td><img src="images/firstdisab.gif" alt="First" width="16" height="16" border="0"></td>
	<% Else %>
	<td><a href="giochieu_list.asp?start=1"><img src="images/first.gif" alt="First" width="16" height="16" border="0"></a></td>
	<% End If %>
<!--previous page button-->
	<% If CLng(PrevStart) = CLng(nStartRec) Then %>
	<td><img src="images/prevdisab.gif" alt="Previous" width="16" height="16" border="0"></td>
	<% Else %>
	<td><a href="giochieu_list.asp?start=<%=PrevStart%>"><img src="images/prev.gif" alt="Previous" width="16" height="16" border="0"></a></td>
	<% End If %>
<!--current page number-->
	<td><input type="text" name="pageno" value="<%=(nStartRec-1)\nDisplayRecs+1%>" size="4"></td>
<!--next page button-->
	<% If CLng(NextStart) = CLng(nStartRec) Then %>
	<td><img src="images/nextdisab.gif" alt="Next" width="16" height="16" border="0"></td>
	<% Else %>
	<td><a href="giochieu_list.asp?start=<%=NextStart%>"><img src="images/next.gif" alt="Next" width="16" height="16" border="0"></a></td>
	<% End If %>
<!--last page button-->
	<% If CLng(LastStart) = CLng(nStartRec) Then %>
	<td><img src="images/lastdisab.gif" alt="Last" width="16" height="16" border="0"></td>
	<% Else %>
	<td><a href="giochieu_list.asp?start=<%=LastStart%>"><img src="images/last.gif" alt="Last" width="16" height="16" border="0"></a></td>
	<% End If %>
	<td><span class="aspmaker">&nbsp;of <%=(nTotalRecs-1)\nDisplayRecs+1%></span></td>
	</tr></table>
	<% If CLng(nStartRec) > CLng(nTotalRecs) Then nStartRec = nTotalRecs
	nStopRec = nStartRec + nDisplayRecs - 1
	nRecCount = nTotalRecs - 1
	If rsEOF Then nRecCount = nTotalRecs
	If nStopRec > nRecCount Then nStopRec = nRecCount %>
	<span class="aspmaker">Records <%= nStartRec %> to <%= nStopRec %> of <%= nTotalRecs %></span>
<% Else %>
	<% If sSrchWhere = "0=101" Then %>
	<span class="aspmaker"></span>
	<% Else %>
	<span class="aspmaker">No records found</span>
	<% End If %>
<% End If %>
		</td>
	</tr>
</table>
</form>
<!--#include file="footer.asp"-->
<%


'-------------------------------------------------------------------------------
' Function SetUpInlineEdit
' - Set up Inline Edit parameters based on querystring parameters
' - Variables setup: sAction, Session(TblKeyName)

Sub SetUpInlineEdit()
	Dim bInlineEdit

	' Get the keys for master table
	If Request.QueryString("a").Count > 0 Then
		sAction = Request.QueryString("a")
		If LCase(sAction) = "edit" Then ' Change to Inline Edit Mode
			bInlineEdit = True
			If Request.QueryString("GiochieuID").Count > 0 Then
				x_GiochieuID = Request.QueryString("GiochieuID")
			Else
				bInlineEdit = False
			End If
			If bInlineEdit Then
				If LoadData() Then
					Session(ewSessionTblKey & "_GiochieuID") = x_GiochieuID ' Set up Inline Edit key
				End If
			End If
		ElseIf LCase(sAction) = "cancel" Then ' Switch out of Inline Edit Mode
			Session(ewSessionTblKey & "_GiochieuID") = "" ' Clear Inline Edit key
		End If
	Else
		sAction = Request.Form("a_list")
		If LCase(sAction) = "update" Then ' Update Record

			' Get fields from form
			x_GiochieuID = Request.Form("x_GiochieuID")
			x_Mota = Request.Form("x_Mota")
			x_gioBD = Request.Form("x_gioBD")
			x_phutBD = Request.Form("x_phutBD")
			If CStr(Session(ewSessionTblKey & "_GiochieuID")&"") = CStr(x_GiochieuID&"") Then
				If InlineEditData() Then
					Session(ewSessionMessage) = "Sửa thành công"
				End If
			End If
		End If
		Session(ewSessionTblKey & "_GiochieuID") = "" ' Clear Inline Edit key
				
	End If
End Sub


'-------------------------------------------------------------------------------
' Function SetUpStartRec
' - Set up Starting Record parameters based on Pager Navigation
' - Variables setup: nStartRec

Sub SetUpStartRec()
	Dim nPageNo

	' Check for a START parameter
	If Request.QueryString(StartRec).Count > 0 Then
		nStartRec = Request.QueryString(StartRec)
		Session(SessionStartRec) = nStartRec
	ElseIf Request.QueryString("pageno").Count > 0 Then
		nPageNo = Request.QueryString("pageno")
		If IsNumeric(nPageNo) Then
			nStartRec = (nPageNo-1)*nDisplayRecs+1
			If nStartRec <= 0 Then
				nStartRec = 1
			ElseIf nStartRec >= ((nTotalRecs-1)\nDisplayRecs)*nDisplayRecs+1 Then
				nStartRec = ((nTotalRecs-1)\nDisplayRecs)*nDisplayRecs+1
			End If
			Session(SessionStartRec) = nStartRec
		Else
			nStartRec = Session(SessionStartRec)
			If Not IsNumeric(nStartRec) Or nStartRec = "" Then
				nStartRec = 1 ' Reset start record counter
				Session(SessionStartRec) = nStartRec
			End If
		End If
	Else
		nStartRec = Session(SessionStartRec)
		If Not IsNumeric(nStartRec) Or nStartRec = "" Then
			nStartRec = 1 'Reset start record counter
			Session(SessionStartRec) = nStartRec
		End If
	End If
End Sub

'-------------------------------------------------------------------------------
' Function ResetCmd
' - Clear list page parameters
' - RESET: reset search parameters
' - RESETALL: reset search & master/detail parameters
' - RESETSORT: reset sort parameters

Sub ResetCmd()
	Dim sCmd

	' Get Reset Cmd
	If Request.QueryString("cmd").Count > 0 Then
		sCmd = Request.QueryString("cmd")

		' Reset Search Criteria
		If LCase(sCmd) = "reset" Then
			Call ResetSearch()

		' Reset Search Criteria & Session Keys
		ElseIf LCase(sCmd) = "resetall" Then
			Call ResetSearch()

		' Reset Sort Criteria
		ElseIf LCase(sCmd) = "resetsort" Then
			sOrderBy = ""
			Session(ewSessionTblOrderBy) = sOrderBy
			If Session(ewSessionTblSort & "_x_GiochieuID") <> "" Then Session(ewSessionTblSort & "_x_GiochieuID") = ""
			If Session(ewSessionTblSort & "_x_Mota") <> "" Then Session(ewSessionTblSort & "_x_Mota") = ""
			If Session(ewSessionTblSort & "_x_gioBD") <> "" Then Session(ewSessionTblSort & "_x_gioBD") = ""
			If Session(ewSessionTblSort & "_x_phutBD") <> "" Then Session(ewSessionTblSort & "_x_phutBD") = ""
		End If

		' Reset Start Position (Reset Command)
		nStartRec = 1
		Session(ewSessionTblStartRec) = nStartRec
	End If
End Sub
%>
<%

'-------------------------------------------------------------------------------
' Function LoadData
' - Load Data based on Key Value
' - Variables setup: field variables

Function LoadData()

	'response.write(Request("GiochieuID"))
	t_SessionID = Request("GiochieuID")
	
	Dim rs, sSql, sFilter
	sFilter = "[SessionID] = "
	sFilter = sFilter & AdjustSql(t_SessionID)
	sSql = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, sFilter, "")
	Set rs = Server.CreateObject("ADODB.Recordset")
	
	'response.write(sSQL)
	rs.Open sSql, adoCon
	If rs.Eof Then
		LoadData = False
	Else
		LoadData = True
		rs.MoveFirst

		' Get the field contents
		x_GiochieuID = rs("SessionID")
		x_Mota = rs("Description")
		x_gioBD = rs("HourStart")
		x_phutBD = rs("MinuteStart")
		
		Session("SessionID") = t_SessionID
								
	End If
	rs.Close
	Set rs = Nothing
End Function
%>
<%

'-------------------------------------------------------------------------------
' Function EditData
' - Edit Data based on Key Value
' - Variables used: field variables

Function InlineEditData()
	Dim rs, sSql, sFilter
	'sFilter = ewSqlKeyWhere
	'sFilter = Replace(sFilter, "@GiochieuID", AdjustSql(x_GiochieuID)) ' Replace key value
	'sSql = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, sFilter, "")
	sFilter = "[SessionID] = "
	sFilter = sFilter & AdjustSql(Session("SessionID"))
	sSql = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, sFilter, "")
	Set rs = Server.CreateObject("ADODB.Recordset")
	rs.CursorLocation = 3
	
	Dim t_Mota
	Dim t_gioBD
	Dim t_phutBD
	
	t_Mota = Request.Form("x_Mota")
	t_gioBD = Request.Form("x_gioBD")
	t_phutBD = Request.Form("x_phutBD")
	
	'response.write("ID = " & Session("SessionID")) ' & " alo Tuan day")
	'response.write("<br>des = " & t_Mota) ' & " alo Tuan day")
	'response.write("<br>hou = " & t_gioBD) ' & " alo Tuan day")
	'response.write("<br>min = " & t_phutBD) ' & " alo Tuan day")
	
	rs.Open sSql, adoCon, 1, 2

	' clone old and new rs object
	Dim rsold, rsnew
	Set rsold = rs.Clone(1)
	rsold.Requery()
	Set rsnew = rs.Clone(1)
	If rs.Eof Then
		InlineEditData = False ' Update Failed
	Else

		' Field GiochieuID
		sTmp = Session("SessionID")
		If Not IsNumeric(sTmp) Then
			sTmp = 0
		Else
			sTmp = CLng(sTmp)
		End If
		rs("SessionID") = sTmp

		' Field Mota
		sTmp = Trim(t_Mota)
		If Trim(sTmp) = "" Then sTmp = Null
		rs("Description") = sTmp

		' Field gioBD
		sTmp = t_gioBD
		If Not IsNumeric(sTmp) Then
			sTmp = Null
		Else
			sTmp = CLng(sTmp)
		End If
		rs("HourStart") = sTmp

		' Field phutBD
		sTmp = t_phutBD
		If Not IsNumeric(sTmp) Then
			sTmp = Null
		Else
			sTmp = CLng(sTmp)
		End If
		rs("MinuteStart") = sTmp

		' Call updating event
		If Recordset_Updating(rs, rsnew) Then
			rs.Update
			InlineEditData = True
		Else
			rs.CancelUpdate
			InlineEditData = False
		End If
	End If

	' Call updated event
	If InlineEditData Then
		Call Recordset_Updated(rsold, rsnew)
	End If
	rs.Close
	Set rs = Nothing
	rsold.Close
	Set rsold = Nothing
	rsnew.Close
	Set rsnew = Nothing
End Function

'-------------------------------------------------------------------------------
' Recordset updating event

Function Recordset_Updating(rsold, rsnew)
	On Error Resume Next

	' Please enter your customized codes here
	Recordset_Updating = True
End Function

'-------------------------------------------------------------------------------
' Recordset updated event

Sub Recordset_Updated(rsold, rsnew)
	On Error Resume Next
End Sub
%>
